﻿using DotNetCore.CAP;
using System;
using System.Collections.Generic;
using System.Text;
using Yozeev.BusinessLogic.DomainService;
using Yozeev.Common.Generators;

namespace Yozeev.Consumers
{
    public class ActivityConsumer : ISubscriberService, ICapSubscribe
    {
        private readonly ActivityManager _manager;

        private readonly IGenerator _generator;

        public ActivityConsumer(ActivityManager activityManager, ActivityCodeGenerator generator)
        {
            _generator = generator;
            _manager = activityManager;
        }

        [CapSubscribe("swei.activity.create")]
        public async void OnMessageReceived(string activityId)
        {
            Console.WriteLine("收到创建订单事件 " + activityId);
            var activityCode = _generator.Gen(8);
            await _manager.SetActivityCodeAsync(activityId, activityCode);
        }
    }
}
